var CleanWebpackPlugin = require('clean-webpack-plugin')
var path = require('path')

function resolve (relatedPath) {
  return path.join(__dirname, relatedPath)
}

var pathsToClean = [
  resolve('./dist')
]
var cleanOptions = {
  allowExternal: true
}

const baseConfig = {
  mode: 'production',
  entry: resolve('./src/index.ts'),
  output: {
    filename: 'index.js',
    path: resolve('./dist'),
    libraryTarget: 'umd'
  },
  resolve: {
    extensions: ['.ts']
  },
  module: {
    rules: [
      {
        test: /\.ts?$/,
        exclude: /node_modules/,
        loader: 'ts-loader'
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(pathsToClean, cleanOptions)
  ]
}

module.exports = baseConfig
